package com.wuyu.ibatis.builder;

import com.wuyu.ibatis.config.Configuration;

/**
 * mapper构建帮助类
 */
public class MapperBuilderAssistant {
    /**
     * 当前命名空间
     */
    private String currentNamespace;

    /**
     * 资源路径
     */
    private final String resource;

    /**
     * 配置信息
     */
    private final Configuration configuration;


    public MapperBuilderAssistant(Configuration configuration, String resource) {
        this.resource = resource;
        this.configuration = configuration;
    }

    public String getCurrentNamespace() {
        return currentNamespace;
    }


    public void setCurrentNamespace(String currentNamespace) {
        if (currentNamespace == null) {
            throw new BuilderException("The mapper element requires a namespace attribute to be specified.");
        }

        if (this.currentNamespace != null && !this.currentNamespace.equals(currentNamespace)) {
            throw new BuilderException("Wrong namespace. Expected '"
                    + this.currentNamespace + "' but found '" + currentNamespace + "'.");
        }
        this.currentNamespace = currentNamespace;
    }
}
